home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / music / eked-m1.zoo / src / gm / form_man.c next >
C/C++ Source or Header  |  1995-02-19  |  5KB  |  173 lines

  1. /*
  2.  *  EKED-M1 : Editor for Korg M1 synth; form_man.c : form routines
  3.  *  Copyright (C) 1995 Steven M. Eker (Steven.Eker@brunel.ac.uk)
  4.  *
  5.  *  This program is free software; you can redistribute it and/or modify
  6.  *  it under the terms of the GNU General Public License as published by
  7.  *  the Free Software Foundation; either version 2 of the License, or
  8.  *  (at your option) any later version.
  9.  *
  10.  *  This program is distributed in the hope that it will be useful,
  11.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  *  GNU General Public License for more details.
  14.  *
  15.  *  You should have received a copy of the GNU General Public License
  16.  *  along with this program; if not, write to the Free Software
  17.  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  */
  19.  
  20. #include <stddef.h>
  21. #include <stdio.h>
  22. #include <osbind.h>
  23. #include <gemfast.h>
  24. #include <aesbind.h>
  25. #include <string.h>
  26. #include "gem_man.h"
  27.  
  28. int fm_dialog(OBJECT *tree, int ed, OBJECT *org_tree, int org_ob)
  29. {
  30.   int but;
  31.   GRECT org;
  32.   GRECT pos;
  33.  
  34.   if(org_tree){
  35.     objc_offset(org_tree, org_ob, &org.g_x, &org.g_y);
  36.     org.g_w = org_tree[org_ob].ob_width;
  37.     org.g_h = org_tree[org_ob].ob_height;
  38.   }
  39.   form_center(tree, &pos.g_x, &pos.g_y, &pos.g_w, &pos.g_h);
  40.   form_dial(FMD_START, 0, 0, 0, 0, pos.g_x, pos.g_y, pos.g_w, pos.g_h);
  41.   if(org_tree){
  42.     form_dial(FMD_GROW, org.g_x, org.g_y, org.g_w, org.g_h,
  43.                         pos.g_x, pos.g_y, pos.g_w, pos.g_h);
  44.   }
  45.   objc_draw(tree, 0, MAX_DEPTH, pos.g_x, pos.g_y, pos.g_w, pos.g_h);
  46.   but = fm_form_do(tree, ed) & 0x7fff;
  47.   if(org_tree){
  48.     form_dial(FMD_SHRINK, org.g_x, org.g_y, org.g_w, org.g_h,
  49.                           pos.g_x, pos.g_y, pos.g_w, pos.g_h);
  50.   }
  51.   form_dial(FMD_FINISH, 0, 0, 0, 0, pos.g_x, pos.g_y, pos.g_w, pos.g_h);
  52.   tree[but].ob_state &= ~SELECTED;
  53.   return but;
  54. }
  55.  
  56. static OBJECT *f_tree;
  57. static int f_ed;
  58. static int f_button;
  59. static GRECT f_pos;
  60.  
  61. void fm_begin_dialog(OBJECT *tree, int ed)
  62. {
  63.  
  64.   form_center(tree, &f_pos.g_x, &f_pos.g_y, &f_pos.g_w, &f_pos.g_h);
  65.   form_dial(FMD_START, 0, 0, 0, 0, f_pos.g_x, f_pos.g_y, f_pos.g_w, f_pos.g_h);
  66.   objc_draw(tree, 0, MAX_DEPTH, f_pos.g_x, f_pos.g_y, f_pos.g_w, f_pos.g_h);
  67.   f_tree = tree;
  68.   f_ed = ed;
  69. }
  70.  
  71. int fm_run_dialog()
  72. {
  73.   f_button = fm_form_do(f_tree, f_ed) & 0x7fff;
  74.   return f_button;
  75. }
  76.  
  77. void fm_end_dialog()
  78. {
  79.   form_dial(FMD_FINISH, 0, 0, 0, 0, f_pos.g_x, f_pos.g_y, f_pos.g_w, f_pos.g_h);
  80.   f_tree[f_button].ob_state &= ~SELECTED;
  81. }
  82.   
  83. int fm_form_do(OBJECT *tree, int focus)
  84. {
  85.   int m_x, m_y, m_state, k_state, k_ret, n_clks;
  86.   int r, t, next_ob, cursor = 0, ob;
  87.  
  88.   wind_update(BEG_UPDATE);
  89.   wind_update(BEG_MCTRL);
  90.   if(focus != 0)
  91.     objc_edit(tree, focus, 0, 0, ED_INIT, &cursor);
  92.   for(;;){
  93.     r = evnt_multi(MU_BUTTON | MU_KEYBD,
  94.                    2 + 256, 3, 0,
  95.                    0, 0, 0, 0, 0,
  96.                    0, 0, 0, 0, 0,
  97.                    (int *) NULL, 0L,
  98.                    &m_x, &m_y, &m_state,
  99.                    &k_state, &k_ret, &n_clks);
  100.     if(r & MU_BUTTON){
  101.       ob = objc_find(tree, 0, MAX_DEPTH, m_x, m_y);
  102.       if(ob != -1){
  103.         t = form_button(tree, ob, n_clks, &next_ob);
  104.         if(t == 0)
  105.           break;
  106.         if(next_ob != 0 && next_ob != focus){
  107.           objc_edit(tree, focus, 0, cursor, ED_END, &cursor);
  108.           focus = next_ob;
  109.           objc_edit(tree, focus, 0, 0, ED_INIT, &cursor);
  110.         }
  111.       }
  112.     }
  113.     if(r & MU_KEYBD){
  114.       t = form_keybd(tree, focus, 0, k_ret, &next_ob, &k_ret);
  115.       if(t == 0)
  116.         break;
  117.       if(next_ob != 0 && next_ob != focus){
  118.         objc_edit(tree, focus, 0, cursor, ED_END, &cursor);
  119.         focus = next_ob;
  120.         objc_edit(tree, focus, 0, 0, ED_INIT, &cursor);
  121.       }
  122.       if(k_ret != 0)
  123.         objc_edit(tree, focus, k_ret, cursor, ED_CHAR, &cursor);
  124.     }
  125.   }
  126.   wind_update(END_MCTRL);
  127.   wind_update(END_UPDATE);
  128.   return next_ob;
  129. }
  130.  
  131. char *fm_file_select(char *title, char *mask, char *filename)
  132. {
  133.   static char path[200], file[13];
  134.   char *p;
  135.   int i, but;
  136.  
  137.   p = strrchr(filename, '\\');
  138.   if(p != NULL){    /* assume full path supplied */
  139.     strcpy(path, filename);
  140.     strcpy(path + (p - filename) + 1, mask);
  141.     strcpy(file, p + 1);
  142.   }
  143.   else{            /* otherwise build path from current drive */
  144.     i = Dgetdrv();
  145.     path[0] = 'A' + i;
  146.     path[1] = ':';
  147.     Dgetpath(path + 2, i + 1);
  148.     strcat(path, "\\");
  149.     strcat(path, mask);
  150.     strcpy(file, filename);
  151.   }
  152.   i = (gl_ap_version >= 0x0140) ? fsel_exinput(path, file, &but, title) :
  153.                                   fsel_input(path, file, &but);
  154.   if(!i || !but)
  155.     return (char *) NULL;
  156.   strcpy(strrchr(path, '\\') + 1, file);
  157.   return path;
  158. }
  159.  
  160. void fm_ob_redraw(OBJECT *tree, int ob, GRECT *area)
  161. {
  162.   objc_draw(tree, gm_opaque(tree, ob), MAX_DEPTH, area->g_x, area->g_y,
  163.             area->g_w, area->g_h);
  164. }
  165.  
  166. int fm_alert(int but, int n)
  167. {
  168.   char *alert;
  169.  
  170.   rm_gaddr(R_STRING, n, &alert);
  171.   return form_alert(but, alert);
  172. }
  173.